package com.zjk.storage.core.entity;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.core.io.Resource;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.Optional;

@Setter
@NoArgsConstructor
public class MultipartFileWrapper implements MultipartFile {

    private String name;
    private String originalFileName;
    private String contentType;
    @Getter
    private MultipartFile multipartFile;

    public MultipartFileWrapper(MultipartFile multipartFile){
        this.multipartFile = multipartFile;
    }

    @Override
    public String getName() {
        return Optional.ofNullable(name).orElse(multipartFile.getName());
    }

    @Override
    public String getOriginalFilename() {
        return Optional.ofNullable(originalFileName).orElse(multipartFile.getOriginalFilename());
    }

    @Override
    public String getContentType() {
        return Optional.ofNullable(contentType).orElse(multipartFile.getContentType());
    }

    @Override
    public boolean isEmpty() {
        return multipartFile.isEmpty();
    }

    @Override
    public long getSize() {
        return multipartFile.getSize();
    }

    @Override
    public byte[] getBytes() throws IOException {
        return multipartFile.getBytes();
    }

    @Override
    public InputStream getInputStream() throws IOException {
        return multipartFile.getInputStream();
    }

    @Override
    public void transferTo(Path dest) throws IOException, IllegalStateException {
        multipartFile.transferTo(dest);
    }

    @Override
    public void transferTo(File dest) throws IOException, IllegalStateException {
        multipartFile.transferTo(dest);
    }

    @Override
    public Resource getResource() {
        return multipartFile.getResource();
    }

}
